package com.landinfo.service.impl;

import com.landinfo.domain.CameraInfo;
import com.landinfo.repository.CameraInfoRepository;
import com.landinfo.service.CameraInfoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.List;


@Service
@Transactional
public class CameraInfoServiceImpl implements CameraInfoService {
    @PersistenceContext
    private EntityManager entityManager;

    private final CameraInfoRepository cameraInfoRepository;

    public CameraInfoServiceImpl(CameraInfoRepository cameraInfoRepository) {
        this.cameraInfoRepository = cameraInfoRepository;
    }


    @Override
    public CameraInfo save(CameraInfo cameraInfo) {
        return this.cameraInfoRepository.save(cameraInfo);
    }

    @Override
    public List<CameraInfo> findAll() {
        String sql = String.format("from CameraInfo");
        Query query = entityManager.createQuery(sql);
        List resultList = query.getResultList();
        return resultList;
    }

    @Override
    public List<CameraInfo> queryByName(String name) {
        return null;
    }

    @Override
    public CameraInfo findOne(String id) {
//        return this.cameraInfoRepository.findOne(id);
        return null;
    }

    @Override
    public void delete(String id) {
//        this.cameraInfoRepository.delete(id);
    }
}
